/*
 * trace_traceFuncInfo.c
 *
 *  Created on: 2012/06/07
 *      Author: guanxiaoying
 */

#include "../table.h"
#include "../trace_ast_table.h"

typedef struct _TRACESUBINFO
{
	AST		astSubInfo;
	AST		astTraceStack;
} TRACESUBINFO, *PTRACESUBINFO;


#define TableSize  (sizeof(TRACESUBINFO ))
#define TableType  PTRACESUBINFO
#define stTable stTraceSubInfoManager.memoryBlocks
#define maxTable stTraceSubInfoManager.maxRecordNum
#define  maxNumPerBlk  (stTraceSubInfoManager.astMaxNum_Block)


static TABLEMANAGER stTraceSubInfoManager = {
//		U4                  usIdx;
		0,
//		PSZ				    con_pszName;    constant
		__FILE__,
//		U2					con_usSize;		constant
		TableSize,
//		U2					block_num;	　　　　　　　Reset clear  際　要
		0,
//		S4					astMaxNum_Block;     １回設定のみ
		0,
//		S4					astTabNum_LastPage; 　　　　Reset clear  際　要
		0,
//		S4					astMaxNum_LastPage;     Reset clear  際　要
		0,
//		U4					ulMaxByte;	　　　　　　　　　　クリアしない
		0,
//		U4					con_minPageSize;　　　　　　　　　　constant
		0
};
static VOID resetListener( U4  procid, U2 index )
{
	if( procid == stTraceSubInfoManager.u4Idx )
	{
		if( index > 0 && index < MAX_VOLUMN_OF_TABLE )
		{
			stTable[ index-1] = NULL;
		}
	}
}
static TableType core_getTable( AST index )
{
	TableType temp = (TableType)Check_Com( &stTraceSubInfoManager, resetListener,  index );
	if( temp != NULL ){ return &temp[index%maxNumPerBlk]; } return NULL;
}
static BOOL ClearTable( VOID )
{
	return Clear_Com( &stTraceSubInfoManager );
}
static BOOL AllocTable( AST astReqArg )
{
	return AllocTable_Com( &stTraceSubInfoManager, astReqArg, resetListener );
}
static AST getMaxLineNum( VOID ){
	return maxTable;
}
static AST getStartStackPoint( AST astIndex ){
	TableType pTbl = core_getTable( astIndex );
	if( pTbl == NULL )
	{
		return 0;
	}
	return pTbl->astTraceStack;
}
static AST setStartStackPoint( AST astIndex, AST value ){
	TableType pTbl = core_getTable( astIndex );
	if( pTbl == NULL )
	{
		return 0;
	}
	return pTbl->astTraceStack=value;
}
static AST getFunctionInfo( AST astIndex ){
	TableType pTbl = core_getTable( astIndex );
	if( pTbl == NULL )
	{
		return 0;
	}
	return pTbl->astSubInfo;
}
static AST setFunctionInfo( AST astIndex, AST value ){
	TableType pTbl = core_getTable( astIndex );
	if( pTbl == NULL )
	{
		return 0;
	}
	return pTbl->astSubInfo=value;
}
const TRACEFUNCINFO_ACCESS stTraceFuncAccess ={
		ClearTable,
		AllocTable,
		getMaxLineNum,
		{
				getStartStackPoint,
				setStartStackPoint
		},

		{
				getFunctionInfo,
				setFunctionInfo
		}
};

